
<?php include_once(dirname(__FILE__) . '/../general/head.php'); ?>

<!-- header -->
<?php include_once(dirname(__FILE__) . '/../general/header.php'); ?>

<?php include_once('left.php'); ?>


<div id="page-wrapper">

    <div class="row">
        <div class="col-lg-12">
            <h1 class="page-header">Điều chỉnh kết quả đánh giá thái độ</h1>
        </div>
    </div>

    <?php
    if ($addResult) {
        ?>
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-success">
                    <div class="panel-heading">
                        <?php echo $addResult; ?>
                    </div>
                </div>
            </div>
        </div>
    <?php } ?>

    <div class="panel panel-default">
        <div class="panel-heading">
            Bảng đánh giá
        </div>
        <div class="panel-body">
            <form method="post" action="<?php echo site_url(get_folder($loggedUser['title']).'/attitude_user_details/edit2/' . $beRatedUser['id']); ?>" onsubmit="return check_cmt()">
                <input type="hidden" name="Command" value="Edit" />
                <div class="row">
                    <!--Cột trái-->
                    <div class="col-lg-12">
                        <div class="form-group">
                            <label>Đợt đánh giá</label>
                            <input type="text" name="name" class="form-control" style="width: 50%;" readonly="readonly" value="<?php echo $evaluation['name']; ?>" />
                        </div>

                        <!--Thông tin nhân viên-->
                        <table class="table table-striped table-hover table-bordered">
                            <tr>
                                <td>Code</td>
                                <td><?php echo $beRatedUser['code']; ?></td>
                                <td>Location</td>
                                <td><?php echo $beRatedUser['location']; ?></td>
                            </tr>
                            <tr>
                                <td>Name</td>
                                <td><?php echo $beRatedUser['name']; ?></td>
                                <td>Team leader</td>
                                <td><?php echo $beRatedUser['teamleaderInfo']['name']; ?></td>
                            </tr>
                            <tr>
                                <td>Position</td>
                                <td><?php echo show_human_title($beRatedUser['title']); ?></td>
                                <td>Supervisor</td>
                                <td><?php echo $beRatedUser['supervisorInfo']['name']; ?></td>
                            </tr>
                            <tr>
                                <td>Email</td>
                                <td><?php echo $beRatedUser['email']; ?></td>
                                <td>RSM</td>
                                <td><?php echo $beRatedUser['rsmInfo']['name']; ?></td>
                            </tr>
                        </table>
<!--                        <div class="form-group">
                            <label>Tên nhân viên</label>
                            <input type="text" name="name" class="form-control" style="width: 50%;" readonly="readonly" value="<?php echo $beRatedUser['name']; ?>" />
                        </div>-->

                        <!--Bảng đánh giá-->
                        <table class="table table-striped table-hover">
                            <thead>
                                <tr>
                                    <!--<th width="40px">No</th>-->
                                    <th>Tiêu chí</th>
                                    <th colspan="3" width="40%">Mức độ đánh giá</th>
                                    <th width="20%">Nhận xét</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                $i = 0;
                                foreach ($attitudeCriterias as $eachAC) {
                                    $scores = explode(',', $eachAC->score);
                                    $i++;
                                    ?>
                                    <tr>
                                        <!--<td><?php echo $i; ?></td>-->
                                        <td><?php echo $eachAC->name; ?></td>
                                        <td>
                                            <div class="radio" style="margin-top: auto;">
                                                <label>
                                                    <input type="radio" id="max-<?php echo $eachAC->id; ?>" name="attCriteria-<?php echo $eachAC->id; ?>" value="<?php echo $scores[0]; ?>" 
                                                           <?php echo (($scores[0] == $eachAC->checked) ? 'checked="checked"' : ''); ?> /><font color="green"><b>Thể hiện vượt trội</b></font>
                                                </label>
                                            </div>
                                        </td>
                                        <td>
                                            <div class="radio" style="margin-top: auto;">
                                                <label>
                                                    <input type="radio" name="attCriteria-<?php echo $eachAC->id; ?>" value="<?php echo $scores[1]; ?>" 
                                                           <?php echo (($scores[1] == $eachAC->checked) ? 'checked="checked"' : ''); ?> /><font color="blue"><b>Có thể hiện</b></font>
                                                </label>
                                            </div>
                                        </td>
                                        <td>
                                            <div class="radio" style="margin-top: auto;">
                                                <label>
                                                    <input type="radio" id="min-<?php echo $eachAC->id; ?>" name="attCriteria-<?php echo $eachAC->id; ?>" value="<?php echo $scores[2]; ?>" 
                                                           <?php echo (($scores[2] == $eachAC->checked) ? 'checked="checked"' : ''); ?> /><font color="red"><b>Cần cải thiện</b></font>
                                                </label>
                                            </div>
                                        </td>
                                        <td>
                                            <div class="form-group has-error" style="margin-bottom: auto;">
                                                <textarea name="cmt-<?php echo $eachAC->id; ?>" style="width: 100%;" class="att-cmt"><?php echo $eachAC->comment; ?></textarea>

                                            </div>
                                        </td>
                                    </tr>
                                <?php } ?>
                            </tbody>
                        </table>
                        
                        <div class="form-group">
                            <label>Nhận xét của RSM</label>
                            <textarea name="rsm_comment" class="form-control" rows="5"><?php echo $attDetailResult['rsm_comment']; ?></textarea>
                        </div>

                        <?php if(function_exists('validation_errors') && validation_errors() != ''){ ?>
                        <?php echo validation_errors('<div><font color="red">', '</font></div>'); ?>
                        <?php } ?>
                        <br>
                        <div class="form-group">
                            <input class="btn btn-primary" type="submit" value="Confirm" name="submit-confirm">  
                            &nbsp; 
                            <input class="btn btn-danger" type="submit" value="Reject" name="submit-reject">  
                            &nbsp; 
                            <a href="<?php echo site_url(get_folder($loggedUser['title']).'/attitude_detail_results/confirm'); ?>"> Quay lại danh sách</a>
                        </div>
                    </div>
                </div>
            </form>

        </div>
    </div>
    <br>


</div>
<!-- /#page-wrapper -->
<script>
    function check_cmt()
    {
        var ok = true;
        $('[name^=cmt]').each(function(index) {
            if ($(this).val() == '')
            {
                if ($('[id^=max]:eq(' + index + ')').is(':checked') || $('[id^=min]:eq(' + index + ')').is(':checked'))
                {
                    if ($(this).siblings().length == 0)
                    {
                        $(this).after('<label class="control-label" for="inputError" style="margin-bottom: auto;">Yêu cầu viết nhận xét</label>');

                    }
                    ok = false;
                }
            }
            else
            {
                $(this).siblings().remove();
            }
        });
        
        // kiểm tra nhận xét của rsm
        
//        if ($('[name=rsm_comment]').val() == '')
//            {
//                
//                   
//                        $('[name=rsm_comment]').after('<div><font color="red">Chưa nhập nhận xét của RSM</font></div>');
//                    ok = false;
//            }
//            else
//            {
//                $('[name=rsm_comment]').siblings().remove();
//            }
//        });
        


        if (ok == false)
        {
            return false;
        }
        else
        {
            return true;
        }
    }

</script>

<?php include_once(dirname(__FILE__) . '/../general/footer.php'); ?>